import { getBalance,getCardTransactions } from "../../api/manage";

Page({
  data: {
    balance:0,
    tBalance:0,
    isshow:true,
    records: [],
  },

  onLoad: function() {
    // 页面加载时执行的操作
    const userID = wx.getStorageSync('userID');

    getBalance(userID).then((res) => {
        
      this.setData({
        balance: res.data.balance,
        tBalance:res.data.balance
      });  
    });

    getCardTransactions(userID).then((res) => {
      const processedData = res.data.map(item => {
        return {
          ...item,
          amount: `${item.amount}元`,
          address: `${item.location}`,
          time: `${item.transactionDate}`
        };
      });
      // 将处理后的数据设置到页面的data中
      this.setData({ records: processedData });
    });
  },

  isShow:function(e){
     this.setData({
      isshow: !this.data.isshow
    });
     if(this.data.isshow){
       this.setData({
        balance: this.data.tBalance
      });
     }
     else{
      this.setData({
        balance: "****"
      });
     }
  }
});